package com.swk.path;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 路径问题
 */
@WebServlet("/Path")
public class PathServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public PathServlet() {
        super();
    }

	/**
	 * 转发与重定向
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		System.out.println("in...");
		
		//转发到首页
//		request.getRequestDispatcher("/index.jsp").forward(request, response);
//		this.getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
		
		//重定向到首页
//		response.sendRedirect("/webDetail/index.jsp");
		response.sendRedirect(request.getContextPath() + "/index.jsp");
		
		System.out.println("out...");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
